home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 8 / FM Towns Free Software Collection 8.iso / t_os / otohime / src / lib / szoom.asm < prev    next >
Assembly Source File  |  1994-06-01  |  9KB  |  550 lines

  1. ;            SOUND ZOOM
  2. ;
  3. ;        call from F-BASIC386 or High C
  4. ;    callm address,varptr(source),varptr(new),varptr(param),varptr(work)
  5. ;    void  SZOOM(*sourcesnd,*newsnd,*param,*work)
  6. ;
  7. ;
  8. ;            1990 3  Hiroshi TODA
  9. ;
  10. ;            1993 12 High C 用に改造
  11. ;
  12. ;    param: cycle , amp*10000H , time*10000H
  13. ;    work area = 256Byte
  14. ;
  15. ;
  16.  
  17.     .386p
  18.  
  19.  
  20. param    struc
  21.  
  22.     dd    ?
  23.     dd    ?
  24. source    dd    ?        ; source snd.data address
  25. new    dd    ?        ; new snd.data address
  26. paradd    dd    ?        ; param. address
  27. wadd    dd    ?         ; work address
  28.  
  29. param   ends
  30.  
  31. work    struc
  32.  
  33. ;data area
  34.  
  35. cycle    dd    ?        ; cycle
  36. amp    dd    ?        ; amplitude expand rate
  37. time    dd    ?        ; time expand rate
  38. max    dd    ?        ; max length
  39.  
  40. ;work area
  41.  
  42. rend    dd    ?        ; read end
  43. rated    dd    ?        ; add rate
  44. ratea    dd    ?        ; add buf.
  45. lst1    dd    ?        ; loop start check
  46. lst2    dd    ?        ; loop start
  47. lend1    dd    ?        ; loop end check
  48. lend2    dd    ?        ; loop end
  49. pbuf    dd    ?        ; buf
  50.     dd    ?
  51.     dd    ?
  52. count1    dd    ?        ; cycle count buf.
  53. count2    dd    ?        ; cycle*10000H
  54.  
  55. work    ends
  56.  
  57.  
  58. cseg    segment    dword public use32 'CODE'
  59.     assume    cs:cseg,ds:cseg
  60.  
  61.     public    sndExpand
  62.     db    'sndExpand',9
  63. sndExpand    proc    near
  64.     push    ebp
  65.     mov    ebp,esp
  66.     push    esi
  67.     push    edi
  68.     push    ebx
  69.  
  70.     mov    esi,[ebp].wadd        ; esi <-- work area top add
  71.     mov    ecx,[ebp].paradd    ; ecx <-- para. add.
  72.     xor    edx,edx            ; edx=count
  73. main01:    mov    eax,[ecx][edx*4]    ; para. --> work area
  74.     mov    [esi][edx*4],eax
  75.     inc    edx
  76.     cmp    edx,4
  77.     jb    main01
  78.  
  79.     mov    ebx,[ebp].source    ; ebx <-- source snd. add.
  80.     mov    edi,[ebp].new        ; edi <-- new snd. add.
  81.     xor    edx,edx            ; head trans
  82. main02:    mov    eax,[ebx][edx*4]
  83.     mov    [edi][edx*4],eax
  84.     inc    edx
  85.     cmp    edx,8
  86.     jb    main02
  87.  
  88.     mov    eax,[esi].cycle        ; count set
  89.     cmp    eax,0
  90.     jne    main00
  91.     mov    eax,1
  92.     mov    [esi].cycle,eax
  93. main00:    mov    [esi].count1,eax
  94.     xor    ecx,ecx            ; ecx <-- counter
  95.     mov    eax,[ebx+12]
  96.     mov    [esi].rend,eax
  97.     cmp    eax,0
  98.     je    mainE
  99.     mov    eax,[ebx+16]        ; loop start
  100.     add    eax,ebx
  101.     add    eax,32
  102.     mov    [esi].lst1,eax
  103.     add    eax,[ebx+20]        ; loop end
  104.     mov    [esi].lend1,eax
  105.     add    ebx,32            ; add head(32Byte)
  106.     add    edi,32
  107.     add    [esi].rend,ebx
  108. ;    sub    [esi].rend,1                    ; 1993 12 -1は止める
  109.     xor    eax,eax            ; loop clear
  110.     mov    [esi].lst2,eax
  111.     mov    [esi].lend2,eax
  112.     xor    eax,eax            ; set time rate
  113.     mov    [esi].ratea,eax
  114.     cmp    dword ptr [esi].time,10000H
  115.     jb    main03
  116.     mov    eax,[esi].time        ; hi
  117.     sub    eax,10000H
  118.     mov    [esi].rated,eax
  119.     mov    eax,[esi].cycle        ; set count2
  120.     shl    eax,16
  121.     mov    [esi].count2,eax
  122.     jmp    main04
  123. main03:    mov    eax,10000H
  124.     sub    eax,[esi].time
  125.     mov    [esi].rated,eax
  126.     mov    eax,10000H        ; set count2
  127.     sub    eax,[esi].rated
  128.     mul    dword ptr [esi].cycle
  129.     mov    [esi].count2,eax
  130.  
  131. main04:    mov    al,[ebx]        ; trans while zero
  132.     mov    [edi],al
  133.     cmp    ebx,[esi].lst1
  134.     jne    main0A
  135.     mov    [esi].lst2,ecx
  136. main0A:    cmp    ebx,[esi].lend1
  137.     jne    main0B
  138.     mov    [esi].lend2,ecx
  139. main0B:    inc    ecx
  140.     inc    ebx
  141.     inc    edi
  142.     cmp    ebx,[esi].rend
  143.     jae    mainE
  144.     dec    dword ptr [esi].max
  145.     je    mainE
  146.     and    al,7fH
  147.     je    main04
  148.     dec    ebx
  149.     dec    edi
  150.     dec    ecx
  151.     inc    dword ptr [esi].max
  152.     cmp    dword ptr [esi].time,10000H
  153.     jb    main05
  154.     call    hi
  155.     jmp    main06
  156. main05:    call    lw
  157. main06:    cmp    ecx,2000H        ; data min length
  158.     jae    main0D
  159.     cmp    [esi].max,0
  160.     je    main0D
  161.     mov    al,80H
  162. main0C:    mov    [edi],al
  163.     dec    dword ptr [esi].max
  164.     je    main0D
  165.     inc    ecx
  166.     inc    edi
  167.     cmp    ecx,2000H
  168.     jb    main0C
  169. main0D:    mov    edi,[ebp].new        ; edi <-- new snd. add.
  170.     mov    [edi+12],ecx        ; set length
  171.     mov    eax,[esi].lst2        ; set loop point
  172.     cmp    eax,ecx
  173.     jb    main07
  174.     mov    eax,ecx
  175.     dec    eax
  176. main07:    mov    [edi+16],eax
  177.     mov    eax,[esi].lend2        ; set loop length
  178.     sub    eax,[esi].lst2
  179.     mov    edx,eax
  180.     add    edx,[edi+16]
  181.     cmp    edx,ecx
  182.     jb    main08
  183.     mov    eax,ecx
  184.     sub    eax,[edi+16]
  185. main08:    mov    [edi+20],eax
  186.  
  187. mainE:
  188.     pop    ebx
  189.     pop    edi
  190.     pop    esi
  191.     mov    esp,ebp
  192.     pop    ebp
  193.     ret
  194.  
  195. hi:    call    red            ; read
  196.     imul    dword ptr [esi].amp
  197.     shrd    eax,edx,16
  198.     call    wr            ; write
  199.     cmp    ebx,[esi].lst1        ; sound loop check
  200.     jne    hi0A
  201.     mov    [esi].lst2,ecx
  202. hi0A:    cmp    ebx,[esi].lend1
  203.     jne    hi0B
  204.     mov    [esi].lend2,ecx
  205. hi0B:    inc    ecx
  206.     dec    dword ptr [esi].max
  207.     je    hiE
  208.  
  209. ;    mov    ax,[edi-2]        ; cross check
  210. ;    cmp    ax,8080H
  211. ;    je    hi00
  212. ;    and    eax,8080H
  213. ;    cmp    eax,80H
  214.  
  215.     call    close_ck
  216.  
  217.     jne    hi03
  218. hi00:    mov    eax,[esi].rated        ; ratea=ratea+rated
  219.     add    [esi].ratea,eax
  220. hi01:    mov    eax,[esi].ratea
  221.     cmp    eax,[esi].count2
  222.     jb    hi03
  223.     sub    eax,[esi].count2
  224.     mov    [esi].ratea,eax
  225.     mov    [esi].pbuf,ebx        ; make wave
  226.     mov    eax,[esi].cycle        ; set cycle count
  227.     mov    [esi].count1,eax
  228. hi02:    inc    ebx            ; loop start
  229.     call    red            ; read
  230.     imul    dword ptr [esi].amp
  231.     shrd    eax,edx,16
  232.     call    wr
  233.     cmp    ebx,[esi].lst1        ; sound loop check
  234.     jne    hi0C
  235.     mov    [esi].lst2,ecx
  236. hi0C:    cmp    ebx,[esi].lend1
  237.     jne    hi0D
  238.     mov    [esi].lend2,ecx
  239. hi0D:    inc    ecx
  240.     cmp    ebx,[esi].rend
  241.     jae    hiE
  242.     dec    dword ptr [esi].max
  243.     je    hiE
  244.  
  245. ;    mov    ax,[edi-2]
  246. ;    cmp    ax,8080H
  247. ;    je    hi0E
  248. ;    and    eax,8080H
  249. ;    cmp    eax,80H
  250.  
  251.     call    close_ck
  252.  
  253.     jne    hi02            ; loop end
  254. hi0E:    dec    dword ptr [esi].count1    ; cycle count
  255.     jne    hi02
  256.     mov    ebx,[esi].pbuf        ; buf. -> ebx
  257.     dec    edi            ; 1Byte over write
  258.  
  259. ;    dec        edi
  260. ;    mov        eax,[edi]
  261. ;    call    red2
  262. ;    sar        eax,2
  263. ;    call    wr
  264.  
  265. ;    call    red
  266. ;    imul    dword ptr [esi].amp
  267. ;    shrd    eax,edx,16
  268. ;    sar        eax,2
  269.  
  270.     mov        eax,[edi-1]
  271.     call    red2
  272.     push    eax                ; over write data を push
  273.  
  274.     inc        ebx                ; 1つ先と平均化
  275.     call    red            ; read
  276.     dec        ebx
  277.  
  278.     imul    dword ptr [esi].amp
  279.     shrd    eax,edx,16
  280.  
  281.     add        [esp],eax
  282.     pop        eax
  283.     sar        eax,1            ; over write data と 平均化
  284.  
  285.     call    wr
  286.     jmp    hi01
  287. hi03:    inc    ebx
  288.     cmp    ebx,[esi].rend
  289.     jb    hi
  290. hiE:    ret
  291.  
  292. lw:    call    red            ; read
  293.     imul    dword ptr [esi].amp
  294.     shrd    eax,edx,16
  295.     call    wr            ; write
  296.     cmp    ebx,[esi].lst1        ; sound loop check
  297.     jne    lw0A
  298.     mov    [esi].lst2,ecx
  299. lw0A:    cmp    ebx,[esi].lend1
  300.     jne    lw0B
  301.     mov    [esi].lend2,ecx
  302. lw0B:    inc    ecx
  303.     dec    dword ptr [esi].max
  304.     je    lwE
  305.  
  306. ;    mov    ax,[edi-2]        ; cross check
  307. ;    cmp    ax,8080H
  308. ;    je    lw00
  309. ;    and    eax,8080H
  310. ;    cmp    eax,80H
  311.  
  312.     call    close_ck
  313.  
  314.     jne    lw03
  315. lw00:    mov    eax,[esi].rated        ; ratea=ratea+rated
  316.     add    [esi].ratea,eax
  317. lw01:    mov    eax,[esi].ratea
  318.     cmp    eax,[esi].count2
  319.     jb    lw03
  320.     sub    eax,[esi].count2    ; delete wave
  321.     mov    [esi].ratea,eax
  322.     mov    [esi].pbuf,ecx        ; count(ecx,edi,max) -> buf.
  323.     mov    [esi].pbuf+4,edi
  324.     mov    eax,[esi].max
  325.     mov    [esi].pbuf+8,eax
  326.     mov    eax,[esi].cycle        ; set cycle count
  327.     mov    [esi].count1,eax
  328. lw02:    inc    ebx            ; loop start
  329.     call    red            ; read
  330.     imul    dword ptr [esi].amp
  331.     shrd    eax,edx,16
  332.     call    wr
  333.     cmp    ebx,[esi].lst1        ; sound loop check
  334.     jne    lw0C
  335.     mov    [esi].lst2,ecx
  336. lw0C:    cmp    ebx,[esi].lend1
  337.     jne    lw0D
  338.     mov    [esi].lend2,ecx
  339. lw0D:    inc    ecx
  340.     cmp    ebx,[esi].rend
  341.     jae    lwE
  342.     dec    dword ptr [esi].max
  343.     je    lwE
  344.  
  345. ;    mov    ax,[edi-2]
  346. ;    cmp    ax,8080H
  347. ;    je    lw0E
  348. ;    and    eax,8080H
  349. ;    cmp    eax,80H
  350.  
  351.     call    close_ck
  352.  
  353.     jne    lw02            ; loop end
  354. lw0E:    dec    dword ptr [esi].count1    ; cycle count
  355.     jne    lw02
  356.     mov    ecx,[esi].pbuf        ; buf. -> count(ecx,edi)
  357.     mov    edi,[esi].pbuf+4
  358.     mov    eax,[esi].pbuf+8
  359.     mov    [esi].max,eax
  360.     dec    edi            ; 1Byte over write
  361.  
  362. ;    dec        edi
  363. ;    mov        eax,[edi]
  364. ;    call    red2
  365. ;    sar        eax,2
  366. ;    call    wr
  367.  
  368. ;    call    red
  369. ;    imul    dword ptr [esi].amp
  370. ;    shrd    eax,edx,16
  371. ;    sar        eax,2
  372.  
  373.     mov        eax,[edi-1]
  374.     call    red2
  375.     push    eax                ; over write data を push
  376.  
  377.     inc        ebx                ; 1つ先と平均化
  378.     call    red            ; read
  379.     dec        ebx
  380.  
  381.     imul    dword ptr [esi].amp
  382.     shrd    eax,edx,16
  383.  
  384.     add        [esp],eax
  385.     pop        eax
  386.     sar        eax,1            ; over write data と 平均化
  387.  
  388.     call    wr
  389.     jmp    lw01
  390. lw03:    inc    ebx
  391.     cmp    ebx,[esi].rend
  392.     jb    lw
  393. lwE:    ret
  394.  
  395.  
  396.  
  397. ;    edi-4を境にクロスしてるかをフィルタ(平均化)にかけて判断
  398. ;    eax = 0ならクロス, eax != 0ならノンクロス
  399.  
  400. close_ck:
  401.     push    ecx
  402.     push    edx
  403.  
  404. ;    mov        eax,[edi-8]
  405.     mov        eax,[ebx-2]        ; オリジナルを見るように変更
  406.  
  407.     shld    edx,eax,8
  408.     cmp        dl,80h
  409.     jb        cls00
  410.     mov        dh,dl
  411.     mov        dl,80h
  412.     sub        dl,dh
  413. cls00:
  414.     movsx    edx,dl
  415.     mov        ecx,edx
  416.  
  417.     shld    edx,eax,16
  418.     cmp        dl,80h
  419.     jb        cls01
  420.     mov        dh,dl
  421.     mov        dl,80h
  422.     sub        dl,dh
  423. cls01:
  424.     movsx    edx,dl
  425.     add        ecx,edx
  426.     add        ecx,edx
  427.  
  428.     shld    edx,eax,24
  429.     cmp        dl,80h
  430.     jb        cls02
  431.     mov        dh,dl
  432.     mov        dl,80h
  433.     sub        dl,dh
  434. cls02:
  435.     movsx    edx,dl
  436.     add        ecx,edx
  437.  
  438.     shld    edx,eax,32
  439.     cmp        dl,80h
  440.     jb        cls03
  441.     mov        dh,dl
  442.     mov        dl,80h
  443.     sub        dl,dh
  444. cls03:
  445.     movsx    edx,dl
  446. ;    add        ecx,edx
  447.  
  448.     cmp        ecx,0
  449. ;    jge        cls_no
  450.     jg        cls_no
  451.  
  452. ;    mov        eax,[edi-4]
  453.     mov        eax,[ebx-1]        ; オリジナルを見るように変更
  454.  
  455.     shld    edx,eax,8
  456.     cmp        dl,80h
  457.     jb        cls10
  458.     mov        dh,dl
  459.     mov        dl,80h
  460.     sub        dl,dh
  461. cls10:
  462.     movsx    edx,dl
  463.     mov        ecx,edx
  464.  
  465.     shld    edx,eax,16
  466.     cmp        dl,80h
  467.     jb        cls11
  468.     mov        dh,dl
  469.     mov        dl,80h
  470.     sub        dl,dh
  471. cls11:
  472.     movsx    edx,dl
  473.     add        ecx,edx
  474.     add        ecx,edx
  475.  
  476.     shld    edx,eax,24
  477.     cmp        dl,80h
  478.     jb        cls12
  479.     mov        dh,dl
  480.     mov        dl,80h
  481.     sub        dl,dh
  482. cls12:
  483.     movsx    edx,dl
  484.     add        ecx,edx
  485.  
  486.     shld    edx,eax,32
  487.     cmp        dl,80h
  488.     jb        cls13
  489.     mov        dh,dl
  490.     mov        dl,80h
  491.     sub        dl,dh
  492. cls13:
  493.     movsx    edx,dl
  494. ;    add        ecx,edx
  495.  
  496.     cmp        ecx,0
  497. ;    jle        cls_no
  498.     jl        cls_no
  499.  
  500.     xor        eax,eax
  501.     jmp        cls_end
  502.  
  503. cls_no:
  504.     xor        eax,eax
  505.     sub        eax,1
  506.  
  507. cls_end:
  508.     pop        edx
  509.     pop        ecx
  510.     ret
  511.  
  512.  
  513. ;    WRITE DATA
  514. ;    eax -> pcm data -> [edi] & inc edi
  515.  
  516. wr:    cmp    eax,0            ; write
  517.     js    wr01
  518.     je    wr01
  519.     cmp    eax,128            ; +
  520.     jb    wr02
  521.     mov    eax,127
  522.     jmp    wr02
  523. wr01:    mov    edx,eax            ; -
  524.     mov    eax,128
  525.     sub    eax,edx
  526.     cmp    eax,256-1    ; data255はloopStopの意味があるから除外 1993 12
  527.     jb    wr02
  528.     mov    eax,255-1    ; data255はloopStopの意味があるから除外 1993 12
  529. wr02:    mov    [edi],al
  530.     inc    edi
  531.     ret
  532.  
  533. ;    PCM DATA READ
  534. ;    [ebx] -> output eax
  535.  
  536. red:    mov    al,[ebx]        ; read
  537. red2:    and    eax,0ffH    ; eaxにあるpcm dataをsigned intに変換するときに呼ぶ
  538.     cmp    eax,128
  539.     jb    red01
  540.     mov    edx,eax
  541.     mov    eax,128
  542.     sub    eax,edx
  543. red01:    ret
  544.  
  545. sndExpand    endp
  546.  
  547. cseg    ends
  548.  
  549.     end
  550.